var app = new Vue({
  el: ".login",
  data() {
    return {
      inputtext: {
        email: "", //邮箱
        password: "", //一次密码
        rpassword: "" //二次密码
      },
      istrue: true,
      ischeck: false,
      maskfalse: false,
      theuser: "",
      information: "",
      showprotocol: false,
      refID: "",
      isfalse: false,
      loading:false
    };
  },
  created() {
    if (
      window.sessionStorage.getItem("refererId") &&
      window.sessionStorage.getItem("refererId") != ""
    ) {
      this.refID = window.sessionStorage.getItem("refererId");
    }
  },
  mounted(){
    this.loading=true
  },
  methods: {
    submit() {
      let lang = this.getCookie("lang");
      if (
        this.inputtext.password.length < 6 ||
        this.inputtext.rpassword.length < 6
      ) {
        let timer = setInterval(() => {
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage";
          clearInterval(timer);
          timer = null;
        }, 2000);
        document.getElementsByClassName("errorMessage")[0].className =
          "errorMessage fadeInUp";
        if (lang == "en_US") {
          this.theuser = "Reset Failed";
          this.information = "Password length cannot be less than 6";
        } else if (lang == "zh_TW") {
          this.theuser = "重置失敗";
          this.information = "密碼長度不能小於6";
        } else {
          this.theuser = "重置失败";
          this.information = "密码长度不能小于6";
        }
        return;
      }
      if (this.inputtext.password != this.inputtext.rpassword) {
        let timer = setInterval(() => {
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage";
          clearInterval(timer);
          timer = null;
        }, 2000);
        document.getElementsByClassName("errorMessage")[0].className =
          "errorMessage fadeInUp";
        if (lang == "en_US") {
          this.theuser = "Reset Failed";
          this.information = "Inconsistent password";
        } else if (lang == "zh_TW") {
          this.theuser = "重置失敗";
          this.information = "密碼不壹致";
        } else {
          this.theuser = "重置失败";
          this.information = "密码不一致";
        }
        return;
      }
      if (document.getElementsByClassName("sencode")[0].value == "") {
                let timer=setInterval(() => {
                    document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                    clearInterval(timer)
                    timer=null
                },2000)
                document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
                if (lang == "en_US") {
                    this.theuser = "Reset Failed"
                    this.information = "Please enter verification code"
                } else if (lang == "zh_TW") {
                    this.theuser = "重置失敗"
                    this.information = "請輸入驗證碼"
                } else {
                    this.theuser = "重置失败"
                    this.information = "请输入验证码"
                }
                return
           }
      if (document.getElementsByClassName("sencode")[0].value.length != 6) {
        let timer = setInterval(() => {
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage";
          clearInterval(timer);
          timer = null;
        }, 2000);
        document.getElementsByClassName("errorMessage")[0].className =
          "errorMessage fadeInUp";
        if (lang == "en_US") {
          this.theuser = "Invalid verification code format";
          this.information = "Invalid verification code format";
        } else if (lang == "zh_TW") {
          this.theuser = "驗證碼格式有誤";
          this.information = "驗證碼格式有誤";
        } else {
          this.theuser = "验证码格式有误";
          this.information = "验证码格式有误";
        }
        return;
      }
      let parm = {
        email: this.inputtext.email,
        password: this.inputtext.password,
        checkCode: parseFloat(
          document.getElementsByClassName("sencode")[0].value
        )
      };
      axios.post("/user/forgetPassword", parm).then(res => {
        if (res.data.code == 200) {
          location.href = "/m/singin";
        } else if (res.data.code == -10003) {
          let timer = setInterval(() => {
            document.getElementsByClassName("errorMessage")[0].className =
              "errorMessage";
            clearInterval(timer);
            timer = null;
          }, 2000);
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage fadeInUp";
          if (lang == "en_US") {
            this.theuser = "Reset Failed";
            this.information = "incorrect verification code";
          } else if (lang == "zh_TW") {
            this.theuser = "重置失敗";
            this.information = "驗證碼輸入錯誤";
          } else {
            this.theuser = "重置失败";
            this.information = "验证码输入错误";
          }
          this.old = "";
          this.newp = "";
          this.Confirmnew = "";
          return;
        } else if (res.data.code == -10007) {
          let timer = setInterval(() => {
            document.getElementsByClassName("errorMessage")[0].className =
              "errorMessage";
            clearInterval(timer);
            timer = null;
          }, 2000);
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage fadeInUp";
          if (lang == "en_US") {
            this.theuser = "Reset Failed";
            this.information = "Verification code expired";
          } else if (lang == "zh_TW") {
            this.theuser = "重置失敗";
            this.information = "驗證碼過期";
          } else {
            this.theuser = "重置失败";
            this.information = "验证码过期";
          }
          this.old = "";
          this.newp = "";
          this.Confirmnew = "";
          return;
        } else if (res.data.code == -10009) {
          let timer = setInterval(() => {
            document.getElementsByClassName("errorMessage")[0].className =
              "errorMessage";
            clearInterval(timer);
            timer = null;
          }, 2000);
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage fadeInUp";
          if (lang == "en_US") {
            this.theuser = "Reset Failed";
            this.information = "incorrect verification code";
          } else if (lang == "zh_TW") {
            this.theuser = "重置失敗";
            this.information = "驗證碼輸入錯誤";
          } else {
            this.theuser = "重置失败";
            this.information = "验证码输入错误";
          }
          this.old = "";
          this.newp = "";
          this.Confirmnew = "";
          return;
        }
      });
    },
    sendcode() {
      let lang = this.getCookie("lang");
      let regValid = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
      if (this.inputtext.email == undefined || this.inputtext.email == "") {
        let timer = setInterval(() => {
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage";
          clearInterval(timer);
          timer = null;
        }, 2000);
        document.getElementsByClassName("errorMessage")[0].className =
          "errorMessage fadeInUp";
        if (lang == "en_US") {
          this.theuser = "Reset Failed";
          this.information = "Please fill in the complete information.";
        } else if (lang == "zh_TW") {
          this.theuser = "重置失敗";
          this.information = "郵箱不能為空";
        } else {
          this.theuser = "重置失败";
          this.information = "邮箱不能为空";
        }
        return;
      }
      let parm = {
        email: this.inputtext.email
      };
      axios.post("/user/eamilcheck", parm).then(res => {
        if (res.data.code == 200) {
          let timer = setInterval(() => {
            document.getElementsByClassName("errorMessage")[0].className =
              "errorMessage";
            clearInterval(timer);
            timer = null;
          }, 2000);
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage fadeInUp";
          if (lang == "en_US") {
            this.theuser = "Email does not exist.";
            this.information = "Email does not exist.";
          } else if (lang == "zh_TW") {
            this.theuser = "郵箱不存在";
            this.information = "郵箱不存在";
          } else {
            this.theuser = "邮箱不存在";
            this.information = "邮箱不存在";
          }
        }
        if (res.data.code == -10002) {
          let timer = setInterval(() => {
            document.getElementsByClassName("errorMessage")[0].className =
              "errorMessage";
            clearInterval(timer);
            timer = null;
          }, 2000);
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage fadeInUp";
          if (lang == "en_US") {
            this.theuser = "Sent successfully";
            this.information = "Sent successfully";
          } else if (lang == "zh_TW") {
            this.theuser = "發送成功";
            this.information = "發送成功";
          } else {
            this.theuser = "发送成功";
            this.information = "发送成功";
          }
          let params = {
            type: 7,
            sendTo: this.inputtext.email
          };
          axios.post("/comm/mail/send", params).then(res => {});
          this.isfalse = true;
          let time = 60;
          let that = this;
          document.getElementsByClassName(
            "emailsendNumber"
          )[0].style.background =
            "#e9e9e9";
          let sendtime = setInterval(function() {
            time -= 1;
            document.getElementsByClassName("emailsendNumber")[0].innerHTML =
              time + "s";
            if (time == 0) {
              if (lang == "en_US") {
                document.getElementsByClassName(
                  "emailsendNumber"
                )[0].innerHTML =
                  "send code";
              } else if (lang == "zh_TW") {
                document.getElementsByClassName(
                  "emailsendNumber"
                )[0].innerHTML =
                  "發送驗證碼";
              } else {
                document.getElementsByClassName(
                  "emailsendNumber"
                )[0].innerHTML =
                  "发送验证码";
              }
              document.getElementsByClassName(
                "emailsendNumber"
              )[0].style.background =
                "white";
              that.isfalse = false;
              clearInterval(sendtime);
            }
          }, 1000);
        }
      });
      if (!regValid.test(this.inputtext.email)) {
        let timer = setInterval(() => {
          document.getElementsByClassName("errorMessage")[0].className =
            "errorMessage";
          clearInterval(timer);
          timer = null;
        }, 2000);
        document.getElementsByClassName("errorMessage")[0].className =
          "errorMessage fadeInUp";
        if (lang == "en_US") {
          this.theuser = "Reset Failed";
          this.information = "Please enter the correct email address.";
        } else if (lang == "zh_TW") {
          this.theuser = "重置失敗";
          this.information = "請您輸入正確的郵箱地址";
        } else {
          this.theuser = "重置失败";
          this.information = "请您输入正确的邮箱地址";
        }
        return;
      }
    },
    quickLogin: function(e) {
      //回车及Enter登录
      if (e.keyCode == 13 || e.keyCode == 108) {
        this.login();
      }
    },
    getCookie(cookiename) {
      //获取cookie
      var arr,
        reg = new RegExp("(^| )" + cookiename + "=([^;]*)(;|$)");
      if ((arr = document.cookie.match(reg))) {
        return unescape(arr[2]);
      } else {
        return null;
      }
    },
    CheckAgreement() {
      this.ischeck = !this.ischeck;
    },
    closeinfo() {
      let timer = setInterval(() => {
        document.getElementsByClassName("errorMessage")[0].className =
          "errorMessage";
        clearInterval(timer);
        timer = null;
      }, 2000);
      document.getElementsByClassName("errorMessage")[0].className =
        "errorMessage fadeInUp";
      this.theuser = "";
      this.information = "";
      let BODY = document.getElementsByTagName("body")[0];
      BODY.style.overflowY = "";
    }
  }
});
